import main.FloatObjArrayGrid;
import main.TwoDGrid;

public class FlaPlate {
  private static FloatObjArrayGrid myGrid;
	
  public static void main(String[] args) {
			int dimension=0, lTemp=0, rTemp=0, tTemp=0, bTemp=0;
		/* Parse arguments */
		if(args.length != 10) {
			System.out.println("Launch with -d # -l # -r # -t # -b #");
			return;
		}
		
		for(int i=0; i < args.length - 1; i++) {
			String s = args[i];
			if(s.compareTo("-d") == 0) {
				i++;
				try {
					dimension = Integer.parseInt(args[i]);
					if(dimension < 0)
						throw new java.lang.NumberFormatException("Number should be positive");
				} catch(java.lang.NumberFormatException e) {
					System.out.println("-d expects a postive integer");
					return;
				}
			} else if(s.compareTo("-l") == 0) {
				i++;
				try {
					lTemp = Integer.parseInt(args[i]);
					if(lTemp < 0 || lTemp > 100)
						throw new java.lang.NumberFormatException("Range should be 0-100");
				} catch(java.lang.NumberFormatException e) {
					System.out.println("-l expects an integer between 0 and 100");
					return;
				}
			} else if(s.compareTo("-r") == 0) {
				i++;
				try {
					rTemp = Integer.parseInt(args[i]);
					if(rTemp < 0 || rTemp > 100)
						throw new java.lang.NumberFormatException("Range should be 0-100");
				} catch(java.lang.NumberFormatException e) {
					System.out.println("-r expects an integer between 0 and 100");
					return;
				}
			} else if(s.compareTo("-t") == 0) {
				i++;
				try {
					tTemp = Integer.parseInt(args[i]);
					if(tTemp < 0 || tTemp > 100)
						throw new java.lang.NumberFormatException("Range should be 0-100");
				} catch(java.lang.NumberFormatException e) {
					System.out.println("-t expects an integer between 0 and 100");
					return;
				}
			} else if(s.compareTo("-b") == 0) {
				i++;
				try {
					bTemp = Integer.parseInt(args[i]);
					if(bTemp < 0 || bTemp > 100)
						throw new java.lang.NumberFormatException("Range should be 0-100");
				} catch(java.lang.NumberFormatException e) {
					System.out.println("-b expects an integer between 0 and 100");
					return;
				}
			} else {
				System.out.println("Invalid switch" + s);
				return;
			}
		}
		
		myGrid = new FloatObjArrayGrid(dimension, dimension);
		myGrid.initSideValue(TwoDGrid.SIDE_BOTTOM, new Float(bTemp));
		myGrid.initSideValue(TwoDGrid.SIDE_LEFT, new Float(lTemp));
		myGrid.initSideValue(TwoDGrid.SIDE_RIGHT, new Float(rTemp));
		myGrid.initSideValue(TwoDGrid.SIDE_TOP, new Float(tTemp));
		
		do {
			myGrid.stepGrid();
		} while(!myGrid.isDone());
		
    TwoDGrid.printResults(dimension, myGrid);

	}
}
